package com.lucweb.action;


import com.lucweb.entity.BaseDict;
import com.lucweb.entity.TaskCall;
import com.lucweb.service.BaseDictService;
import com.lucweb.service.CallService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

@Controller("callAction")
@Scope("prototype")
public class CallAction extends ActionSupport{

    @Resource
    private CallService callService;

    @Resource
    private BaseDictService baseDictService;




    private TaskCall taskCall;

    private int taskId;

    //新建接电窗口
    public String newCall(){

        //没有id时设置id
        int bid = callService.getmaxId();

        List<BaseDict> nameList=baseDictService.getListByTypeCode("3");
        List<BaseDict>companyList=baseDictService.getListByTypeCode("2");

        ActionContext.getContext().put("bid",bid);
        ActionContext.getContext().put("nameList",nameList);
        ActionContext.getContext().put("companyList",companyList);


        return "calls";

    }

    //修改接电
    public String editCall(){

        taskCall = callService.gettaskcallById(taskId);

        ActionContext.getContext().put("taskCall", taskCall);

        List<BaseDict>nameList=baseDictService.getListByTypeCode("3");
        List<BaseDict>companyList=baseDictService.getListByTypeCode("2");

        ActionContext.getContext().put("nameList",nameList);
        ActionContext.getContext().put("companyList",companyList);




        System.out.println(taskCall);



        return "calls";

    }

    //删除接电
    public String deleteCall(){

        callService.deletecalltask(taskId);

        //刷新页面
        List<TaskCall>callList=callService.showcall();
        ActionContext.getContext().put("callList",callList);

        return "addcall";

    }

    //接电
    public String saveOrUpdate(){

        System.out.println(taskCall);


        //先保存
        callService.saveOrUpdate(taskCall);

        //刷新页面
        List<TaskCall>callList=callService.showcall();
        ActionContext.getContext().put("callList",callList);

        return "addcall";

    }

    //获取接电列表
    public String callshow(){


        List<TaskCall>callList=callService.showcall();
        ActionContext.getContext().put("callList",callList);

        return "addcall";

    }

    public TaskCall getTaskCall() {
        return taskCall;
    }

    public void setTaskCall(TaskCall taskCall) {
        this.taskCall = taskCall;
    }

    public int getTaskId() {
        return taskId;
    }

    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }


}
